package com.zhxh.nzpos.query;

import java.util.ArrayList;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhxh.nzpos.R;
import com.zhxh.nzpos.model.Stock;

public class StockQueryAdapter extends BaseAdapter {

	private ArrayList<Stock> items;
	private LayoutInflater inflater;
	
	public StockQueryAdapter(LayoutInflater inflater, ArrayList<Stock> dealItems) {
		this.items = dealItems;
		this.inflater = inflater;
	}
	
	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		//if (convertView == null) {
			convertView = inflater.inflate(R.layout.sellout_query_item, null);
			holder = new ViewHolder();
			holder.identifier = (TextView) convertView.findViewById(R.id.goods_identifier_et);
			holder.name = (TextView) convertView.findViewById(R.id.goods_name_et);
			holder.count = (TextView) convertView.findViewById(R.id.goods_count_et);
			holder.price = (TextView) convertView.findViewById(R.id.goods_price_et);
			holder.date = (TextView) convertView.findViewById(R.id.goods_date_et);
			holder.total = (TextView) convertView.findViewById(R.id.goods_total_et);

			
			convertView.setTag(holder);
		//} else {
		//	holder = (ViewHolder) convertView.getTag();
		//}
		
		Stock item = items.get(position);
		if (item != null) {
			holder.identifier.setText(item.getGoodId());
			holder.name.setText(item.getGoodsName());
			holder.count.setText(""+item.getCount());
			//holder.category.setText(""+item.get);
			holder.price.setText(""+item.getPrice());
			holder.total.setText(""+(item.getCount() * item.getPrice()));
			
			holder.date.setText(""+item.getStockDate());
		//	holder.code.setText(""+item.getCode());
		}
		return convertView;
	}

	static class ViewHolder {
		TextView identifier;
		TextView name;
		TextView count;
		TextView price;
		TextView total;
		TextView date;
		//TextView category;
	}
}
